/*
 * modem_driver.c
 *
 *  Created on: 10/07/2013
 *      Author: Santiago Carmona Meco
 */

#include <public/modem_driver.h>

ModemDriverBuffer_t bufferOfDevices[2];

uint8_t bufferOfDeviceIndex=0;
//uint8_t bufferOfDeviceIndex=1;



void init_modem_driver (void)
{

	bufferOfDevices[SSI_BUFFER].bytesWritten=0;
	bufferOfDevices[SGI_BUFFER].bytesWritten=0;
	bufferOfDevices[SSI_BUFFER].readIndex=0;
	bufferOfDevices[SGI_BUFFER].readIndex=0;
	bufferOfDevices[SSI_BUFFER].writeIndex=0;
	bufferOfDevices[SGI_BUFFER].writeIndex=0;
}

void clear_sgi_buffer (void)
{
	bufferOfDevices[SGI_BUFFER].bytesWritten=0;
	bufferOfDevices[SGI_BUFFER].readIndex=0;
	bufferOfDevices[SGI_BUFFER].writeIndex=0;
}

void clear_ssi_buffer (void)
{

	bufferOfDevices[SSI_BUFFER].bytesWritten=0;
	bufferOfDevices[SSI_BUFFER].readIndex=0;
	bufferOfDevices[SSI_BUFFER].writeIndex=0;
}

void clear_string (byte_t * pString, uint32_t length)
{
	uint32_t i=0;

	for (i=0;i<length;i++)
	{
		pString[i]=0;
	}
}

void 	modem_driver_read_handler(void)
{
	bufferOfDevices[bufferOfDeviceIndex].buffer[bufferOfDevices[bufferOfDeviceIndex].writeIndex] = sgi_uart_getchar();
	bufferOfDevices[bufferOfDeviceIndex].writeIndex++;
	if (bufferOfDevices[bufferOfDeviceIndex].writeIndex>=15000)
	{
		bufferOfDevices[bufferOfDeviceIndex].writeIndex=0;
	}
	bufferOfDevices[bufferOfDeviceIndex].bytesWritten++;

}
